﻿using System.IO;
using System.Web;

namespace FileCloud.NET
{
    /// <summary>
    /// Class representing file parameter for multi form upload.
    /// </summary>
    internal class FileParameter
    {
        #region Constructors

        public FileParameter(string filepath)
        {
            FileName = Path.GetFileName(filepath);

            using (var fileStream = new FileStream(filepath, FileMode.Open))
            {
                var fileData = new byte[fileStream.Length];
                fileStream.Read(fileData, 0, fileData.Length);
                FileData = fileData;
            }
        }

        public FileParameter(byte[] file, string filename, string contenttype)
        {
            FileData = file;
            FileName = HttpUtility.UrlEncode(filename);
            ContentType = HttpUtility.UrlEncode(contenttype);
        }

        public FileParameter(byte[] file, string filename) :
            this(file, filename, null)
        { }

        public FileParameter(byte[] file) :
            this(file, null)
        { }

        #endregion

        #region Properties

        public byte[] FileData { get; set; }
        public string FileName { get; set; }
        public string ContentType { get; set; }

        #endregion
    }
}
